// Lindsay Gilmour
// Adam Lusch
// Dan Niceswanger
//
// Computer Graphics Project 2:
// Teapot racing!

#include "Checkpoint.h"

const string Checkpoint::message = "Checkpoint";
int Checkpoint::duration = 0;

Checkpoint::Checkpoint(GLfloat X1, GLfloat Z1, GLfloat X2, GLfloat Z2)
{
	x1 = X1;
	z1 = Z1;
	
	x2 = X2;
	z2 = Z2;
	
	doDraw = true;
}

Checkpoint::~Checkpoint()
{
}

void Checkpoint::draw() const
{
	if (doDraw)
	{
		glEnable(GL_BLEND);
		glPushMatrix();
			glColor4f(1.0, 0.0, 0.0, 0.5);
			glTranslatef(x1, 0.2, z1);	
			glScalef(0.1, 0.8, 0.1);
			glutSolidCube(1.0);
		glPopMatrix();
		glPushMatrix();
			glColor4f(0.0, 0.0, 1.0, 0.5);
			glTranslatef(x2, 0.2, z2);	
			glScalef(0.1, 0.8, 0.1);
			glutSolidCube(1.0);
		glPopMatrix();
	}
}

void Checkpoint::checkpointCleared()
{
	// switch to projection mode
	glMatrixMode(GL_PROJECTION);

	// save previous matrix which contains the 
	//settings for the perspective projection
	glPushMatrix();

	// reset matrix
	glLoadIdentity();

	// set a 2D orthographic projection, width = height = 40
	gluOrtho2D(0.0, 40.0, 0.0, 40.0);

	glMatrixMode(GL_MODELVIEW);
	
	
	
	glLoadIdentity();

	glPushMatrix();
	glPushAttrib(GL_ALL_ATTRIB_BITS);
	glLineWidth(1.6);
	glDisable(GL_LIGHTING);
		glColor3f(0.9f, 0.9f, 0.9f);
			
		glTranslatef(16.0, 5.0, 0.0);
		glScalef(0.0075f, 0.01f, 0.01f);
		for (unsigned int i = 0; i < message.length(); i++)
		{
			glutStrokeCharacter(GLUT_STROKE_MONO_ROMAN, message[i]);
		}
	glPopAttrib();
	glPopMatrix();
	
	
	
	glMatrixMode(GL_PROJECTION);
	glPopMatrix();
	glMatrixMode(GL_MODELVIEW);
	
}
